﻿<?php require_once('../Connections/conexao.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  $updateSQL = sprintf("UPDATE `admin` SET adm_nome=%s, adm_email=%s, adm_login=%s, adm_senha=%s WHERE id_adm=%s",
                       GetSQLValueString($_POST['adm_nome'], "text"),
                       GetSQLValueString($_POST['adm_email'], "text"),
                       GetSQLValueString($_POST['adm_login'], "text"),
                       GetSQLValueString($_POST['adm_senha'], "text"),
                       GetSQLValueString($_POST['id_adm'], "int"));

  mysql_select_db($database_conexao, $conexao);
  $Result1 = mysql_query($updateSQL, $conexao) or die(mysql_error());

  $updateGoTo = "usuario.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}

$colname_rsusuario = "-1";
if (isset($_GET['idadm'])) {
  $colname_rsusuario = $_GET['idadm'];
}
mysql_select_db($database_conexao, $conexao);
$query_rsusuario = sprintf("SELECT * FROM `admin` WHERE id_adm = %s", GetSQLValueString($colname_rsusuario, "int"));
$rsusuario = mysql_query($query_rsusuario, $conexao) or die(mysql_error());
$row_rsusuario = mysql_fetch_assoc($rsusuario);
$totalRows_rsusuario = mysql_num_rows($rsusuario);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- TemplateBeginEditable name="doctitle" -->
<title>Documento sem título</title>
<!-- TemplateEndEditable -->
<!-- TemplateBeginEditable name="head" -->
<!-- TemplateEndEditable -->
</head>

<body>
<table width="960" align="center">
  <tr>
    <td colspan="2">
	<?php include ("../temadmin/cabecalho.php");?>

</td>
  </tr>
  <tr>
    <td colspan="2">
	<?php include "../temadmin/menu_vertical.php";
	?>
    </td>
  </tr>
  <tr>
    <td width="250">
	<?php include "../temadmin/menu.php";?>
    </td>
    <td width="698"><table width="99%">
      <tr>
        <th width="10%" scope="col">&nbsp;</th>
        <th width="80%" scope="col">Editar Usuario Administrativo</th>
        <th width="10%" scope="col">&nbsp;</th>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td><form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
          <table align="center">
            <tr valign="baseline">
              <td nowrap="nowrap" align="right">Nome:</td>
              <td><input type="text" name="adm_nome" value="<?php echo htmlentities($row_rsusuario['adm_nome'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
            </tr>
            <tr valign="baseline">
              <td nowrap="nowrap" align="right">Email:</td>
              <td><input type="text" name="adm_email" value="<?php echo htmlentities($row_rsusuario['adm_email'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
            </tr>
            <tr valign="baseline">
              <td nowrap="nowrap" align="right">Login:</td>
              <td><input type="text" name="adm_login" value="<?php echo htmlentities($row_rsusuario['adm_login'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
            </tr>
            <tr valign="baseline">
              <td nowrap="nowrap" align="right">Senha:</td>
              <td><input type="password" name="adm_senha" value="<?php echo htmlentities($row_rsusuario['adm_senha'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
            </tr>
            <tr valign="baseline">
              <td nowrap="nowrap" align="right">&nbsp;</td>
              <td><input type="submit" value="Atualizar registro" /></td>
            </tr>
          </table>
          <input type="hidden" name="MM_update" value="form1" />
          <input type="hidden" name="id_adm" value="<?php echo $row_rsusuario['id_adm']; ?>" />
        </form></td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
    </table>
   	
    </td>
  </tr>
  <tr>
    <td colspan="2">
	<?php include ("../temadmin/rodape.php");?>
    </td>
  </tr>
</table>
<p>&nbsp;</p>
</body>
</html>
<?php
mysql_free_result($rsusuario);
?>
